package ar.uba.fi.taller2.cmmiassistant.frontend.adaptadores.tabla;

import java.util.ArrayList;
import java.util.List;

import javax.swing.ListSelectionModel;
import javax.swing.event.ListSelectionEvent;

public class TableSelectionAdapter {

    private static final TableSelectionAdapter instance = new TableSelectionAdapter();
    
    public static TableSelectionAdapter instance() {
        return instance;
    }
    
    /**
     * pre : se ha despachado el ListSelectionEvent <code>evento</code>.
     * post: devuelve los indices de los items seleccionados. 
     * 
     * @param evento
     * @return
     */
    public List<Integer> getSelectedItems(ListSelectionEvent evento) {

        List<Integer> selectedItems = new ArrayList<Integer>();

        ListSelectionModel selectionModel = (ListSelectionModel) evento
                .getSource();

        if (! selectionModel.isSelectionEmpty()) {

            /* analiza todo el rango de elementos seleccionados */
            for (int indice = evento.getFirstIndex(); indice <= evento
                    .getLastIndex(); indice++) {

                if (selectionModel.isSelectedIndex(indice)) {

                    selectedItems.add(indice);
                }
            }
        }

        return selectedItems;
    }

    public int getSelectedItem(ListSelectionEvent evento) {

        
        
        return 0;
    }
}
 